package 验证nomic的不同前缀差异;

import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.commons.io.FileUtils;
import org.apache.commons.math3.linear.ArrayRealVector;
import 中国.易.工具.Http工具;
import 中国.易.工具.Json工具;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

public class 是否支持中文
{
    public static void main(String[] args) throws IOException, InterruptedException
    {
        String[] 图片地址 = new String[6];
        图片地址[0] = "D:\\data\\image\\1-1.jpg";
        图片地址[1] = "D:\\data\\image\\1-2.jpg";
        图片地址[2] = "D:\\data\\image\\1-3.jpg";
        图片地址[3] = "D:\\data\\image\\2-1.jpg";
        图片地址[4] = "D:\\data\\image\\2-2.jpg";
        图片地址[5] = "D:\\data\\image\\2-3.jpg";

        List<ArrayRealVector> 图片向量 = new ArrayList<>(图片地址.length);

        for (String i : 图片地址)
        {
            HttpResponse<String> fh = Http工具.form方式发送文件请求("http://192.168.1.241:8907/img", "1.jpg", "jpg",
                    "file", FileUtils.openInputStream(new File(i)), HttpResponse.BodyHandlers.ofString());

            double[][] ds = Json工具.字符串转对象(fh.body(), new TypeReference<>()
            {
            });

            图片向量.add(new ArrayRealVector(ds[0]));
        }

        String[] 文字 = new String[3];
        文字[0] = "search_query: dog";
        文字[1] = "clustering: dog";
        文字[2] = "classification: dog";

        List<ArrayRealVector> 文字向量 = new ArrayList<>(图片地址.length);

        HttpClient httpClient = HttpClient.newHttpClient();
        for (String i : 文字)
        {
            HttpRequest request = HttpRequest.newBuilder()
                    .uri(URI.create("http://192.168.1.241:8907/txt?i=" + URLEncoder.encode(i, StandardCharsets.UTF_8)))
                    .GET().version(HttpClient.Version.HTTP_1_1).build();

            HttpResponse<String> fh = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
            double[][] ds = Json工具.字符串转对象(fh.body(), new TypeReference<>()
            {
            });
            文字向量.add(new ArrayRealVector(ds[0]));
        }

        for (ArrayRealVector t : 文字向量)
        {
            System.out.println("-------------");

            for (ArrayRealVector i : 图片向量)
            {
                System.out.println(i.cosine(t));
            }
        }

    }
}
